package tt.dz.mvc.controller.openapi;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import tt.dz.dao.ext.system.OmsOperationSpListDao;
import tt.dz.entity.base.JsonCommon;
import tt.dz.entity.base.JsonForList;
import tt.dz.entity.charger.OmsCharger;
import tt.dz.entity.charger.OmsChargerBespeakBillRecord;
import tt.dz.entity.charger.OmsChargerChargeBillRecord;
import tt.dz.entity.station.OmsStation;
import tt.dz.entity.station.OmsStationLocation;
import tt.dz.entity.system.OmsOperList;
import tt.dz.entity.system.OmsOperationSpList;
import tt.dz.mvc.controller.base.BaseAction;
import tt.dz.service.imp.middleware.Ev3c2EncapsulationServiceImpl;
import tt.dz.service.middleware.OmsBespeakService;
import tt.dz.service.middleware.OmsChargeService;
import tt.dz.service.sys.BillService;
import tt.dz.service.sys.ChargerService;
import tt.dz.service.sys.EnterpriseService;
import tt.dz.service.sys.OperListService;
import tt.dz.service.sys.StationService;
import tt.dz.util.ActionUtils;
import tt.dz.util.OmsConstant;
import tt.dz.util.OmsConstant.MsgCodeEnum;
import tt.dz.util.StringUtil;

/**
 * enterpriselogins qi企业级用户操作
 * 
 * @author wangtao
 *
 */
@Controller
public class EnterpriseController {
	private static Logger log = LoggerFactory.getLogger(EnterpriseController.class);

	public static final String OperIdPrefix  = "userId_";
	public static final String AccountPrefix  = "account_";
	
	@Autowired
	@Qualifier("enterpriseService")
	private EnterpriseService enterpriseService;
	@Autowired
	private StationService stationService;
	@Autowired
	private ChargerService chargerService;
	@Autowired
	public OmsChargeService omsChargeService;
	@Autowired
	public OmsBespeakService omsBespeakService;
	@Autowired
	public BillService billService;
	@Autowired
	@Qualifier(value = "operatorService")
	private OperListService operatorServiceImpl;
	@Autowired
	OmsOperationSpListDao omsOperationSpListDao;
	// /**
	// * 第三方企业登录
	// * @author wangtao
	// * @param request
	// * @param response
	// * @return
	// * @throws Exception
	// */
	// @RequestMapping(value = "/enterpriselogins/enterpriselogin")
	// @ResponseBody
	// public JsonCommon<?> login(HttpServletRequest request,
	// HttpServletResponse response) throws Exception {
	//
	// String account = request.getParameter("account");
	// String password = request.getParameter("password");
	// JsonCommon<?> json = enterpriseService
	// .thirdPartLogin(account, password);
	// // 判断登录成功
	// if (json != null
	// && MsgCodeEnum.SUCCESS.getMsgCode().equals(json.getCode())) {
	// if (StringUtils.isEmpty(account)) {
	// json.setCode(MsgCodeEnum.ERROR400.getMsgCode());
	// json.setMsg("没有访问权限");
	// }
	// } else {
	// if (null == json.getCode() || null == json.getMsg()
	// || "".equals(json.getCode()) || "".equals(json.getMsg())) {
	// json.setCode(MsgCodeEnum.OTHER_LOGIN_ERROR.getMsgCode());
	// json.setMsg(MsgCodeEnum.OTHER_LOGIN_ERROR.getMsgInfo());
	// }
	// }
	// return json;
	// }

	/**
	 * 运营商用户登录
	 * 
	 * @author pengyu
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/enterpriselogins/enterpriselogin", method = RequestMethod.POST)
	@ResponseBody
	public JsonCommon<?> login(HttpServletRequest request, HttpServletResponse response) throws Exception {

		String account = request.getParameter("account");
		String password = request.getParameter("password");
		// 简单登录
		OmsOperList operAccount = operatorServiceImpl.getOper(account);
		if (operAccount == null) {
			return new JsonCommon("404", "账户 " + account + " 不存在");
		}
		OmsOperList oper = operatorServiceImpl.simpleLogin(account, password);
		if (oper == null) {
			return new JsonCommon("405", "账户 " + account + " 密码不正确");
		}
		String entityId = oper.getEntity_id();
		//查询运营商是否存在
		OmsOperationSpList omsOperationSpListQuery = new OmsOperationSpList();
		omsOperationSpListQuery.setOper_merchant_id(entityId);
		omsOperationSpListQuery.setValid_flag(1);
		OmsOperationSpList sp =  omsOperationSpListDao.findOneExample(omsOperationSpListQuery , null, null);
		if(sp==null){
			return new JsonCommon("406", "账户 " + account + " 没有对应的运营商");
		}
		//生成token
		String token = ActionUtils.genarateUserToken(oper);
		oper.setToken(token);
		oper.setPassword(null);//密码不返回给运营商用户
		HttpSession session = request.getSession();
//		session.invalidate();
//		session.setAttribute(OperIdPrefix+oper.getOper_id(),oper);
		session.setAttribute(AccountPrefix+account,oper);
//		session.setAttribute(BaseAction.CommonParam.SESSION_USER, oper);
//		session.setAttribute("login_oper_id", oper.getOper_id());
//		session.setAttribute("login_entity_type", String.valueOf(oper.getEntity_type()));
//		session.setAttribute("login_super_flag", oper.getIsSupper().toString());
		// new_session.setAttribute("change_password", oper.getPwdchg_ind());
		return new JsonCommon(oper, OmsConstant.SuccessCodeEnum.SuccessCode.value(),
				OmsConstant.SuccessCodeEnum.SuccessCode.desc());
	}

	/**
	 * 查询预约记录
	 * 
	 * @param request
	 *            token （数据获取的授权码）必传 userPayCard: 用户卡号 必传 pageNo: 开始记录数 必传 pageSize:
	 *            返回记录数 必传 bespeak_current_num 预约流水号
	 * @param response
	 *            JsonForList<OmsChargerBespeakBillRecord>
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/enterpriselogins/findBespeakFromUserCard", method = RequestMethod.POST)
	@ResponseBody
	public JsonForList<?> findBespeakFromUserCard(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// RedisClient.get(key)
		// java http 头文件取token 通用方法：通过用户账号 和 token 来验证是否已登录
		String account = request.getParameter("account");
		String token = request.getParameter("token");
		boolean flag = isLogin(account,token,request);
		if(flag ==false) {
			return new JsonForList<>(null,"404","token验证失败");
		}
		
		String userPayCard = request.getParameter("userPayCard");
		String pageNo = request.getParameter("pageNo");
		String pageSize = request.getParameter("pageSize");
		String bespeak_serial_number = request.getParameter("bespeak_current_num");

		JsonForList<OmsChargerBespeakBillRecord> jsonForlist = new JsonForList<OmsChargerBespeakBillRecord>();
		if (StringUtil.isBlank(userPayCard) || StringUtil.isBlank(pageNo) || StringUtil.isBlank(pageSize)) {
			jsonForlist.setCode(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgCode());
			jsonForlist.setMsg(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgInfo());
			return jsonForlist;
		}
		// 如果有预约流水号，直接查
		if (StringUtil.isNotBlank(bespeak_serial_number)) {
			return this.omsBespeakService.findBespeakBySeriaNoAndUserCard(userPayCard, bespeak_serial_number);
		}
		// 如果没有传预约流水，返回所有该userCard的记录
		else {
			return this.omsBespeakService.findListByUserCard(userPayCard, pageNo, pageSize);
		}

	}


	/**
	 * 查询充电记录
	 * 
	 * @param request
	 *            token （数据获取的授权码）必传
	 * @param response
	 *            userPayCard:用户卡号 必传 pageNo: 开始记录数 必传 pageSize: 返回记录数 必传
	 *            serial_number 充电流水号 流水号为38位 offline_is_pay 是否结算 0 线下未结算,1 线下已结算，2
	 *            线上未结算 ，3 线上已结算 企业用户 为线上
	 * @return JsonForList<OmsChargerChargeBillRecord>
	 * @throws Exception
	 */
	@RequestMapping(value = "/enterpriselogins/findChargeFromUserCard", method = RequestMethod.POST)
	@ResponseBody
	public JsonForList<?> findChargeFromUserCard(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String userPayCard = request.getParameter("userPayCard");
		String pageNo = request.getParameter("pageNo");
		String pageSize = request.getParameter("pageSize");
		String charge_jrnl = request.getParameter("serial_number");
		String offline_is_pay = request.getParameter("offline_is_pay");
		String strLeft = "";
		String strRight = "";
		JsonForList<OmsChargerChargeBillRecord> jsonForlist = new JsonForList<OmsChargerChargeBillRecord>();
		try {
			// 流水号002830000000006701201605181424370001
			/**
			 * 0028300000000067桩号01枪口好20160518142437时间0001
			 */
			strLeft = charge_jrnl.substring(charge_jrnl.length() - 18);// 先去掉前18位桩号
																		// 枪口号
			strRight = strLeft.substring(0, 14);// 截取14位日期格式
			EnterpriseController.stringToDate(strRight, "yyyyMMddHHmmss");// 转化成date
																			// 如果抛异常
																			// 说明格式不对
		} catch (ParseException e) {
			// 如果throw java.text.ParseException或者NullPointerException，就说明格式不对
			jsonForlist.setCode(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgCode());
			jsonForlist.setMsg(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgInfo());
		}
		// List<OmsChargerChargeBillRecord> lsOmsChargerChargeBillRecord = new
		// ArrayList<OmsChargerChargeBillRecord>();
		if (userPayCard == null || "".equals(userPayCard) || pageNo == null || "".equals(pageNo) || pageSize == null
				|| "".equals(pageSize)) {
			jsonForlist.setCode(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgCode());
			jsonForlist.setMsg(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgInfo());
		}

		// 如果有充电流水号，直接查
		if (StringUtil.isNotBlank(charge_jrnl)) {
			String conditionSql = " a where a.charge_jrnl='" + charge_jrnl + "' and valid_flag=1";
			if (offline_is_pay != null || !"".equals(offline_is_pay)) {
				conditionSql += " and a.offline_is_pay=" + offline_is_pay;
			}
			List<OmsChargerChargeBillRecord> list = this.billService
					.findChargeBillsWithCondition(new OmsChargerChargeBillRecord(), conditionSql, 1);
			if (list.size() > 0) {
				jsonForlist.setCode(MsgCodeEnum.SUCCESS.getMsgCode());
				jsonForlist.setMsg(MsgCodeEnum.SUCCESS.getMsgInfo());
				jsonForlist.setList(list);
			} else {
				jsonForlist.setCode(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgCode());
				jsonForlist.setMsg(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgInfo());
			}
		}
		// 如果没有传充电流水，返回所有该userCard的记录
		else {// valid_flag=1 有效标记 1为有效
			String conditionSql = " a where a.user_pay_card='" + userPayCard + "' " + "and valid_flag=1";
			if (offline_is_pay != null || !"".equals(offline_is_pay)) {
				conditionSql += " and a.offline_is_pay=" + offline_is_pay;
			}
			List<OmsChargerChargeBillRecord> list = this.billService
					.findChargeBillsWithCondition(new OmsChargerChargeBillRecord(), conditionSql, 1);
			if (list.size() > 0) {
				jsonForlist.setCode(MsgCodeEnum.SUCCESS.getMsgCode());
				jsonForlist.setMsg(MsgCodeEnum.SUCCESS.getMsgInfo());
				jsonForlist.setList(list);
			} else {
				jsonForlist.setCode(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgCode());
				jsonForlist.setMsg(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgInfo());
			}

		}

		return jsonForlist;
	}

	/**
	 * 3.6 电桩控制(控制电桩预约、取消预约、充电、关闭充电)
	 * 
	 * @param request
	 *            {"charger_id" :电桩端口号 "port_no" : 电口编号 "qr_code" : 电桩二维码号 , code
	 *            [操作编号（1;// 自动充满 2;// 停止充满 3;// 预约 4;// 取消预约 userPayCard:用户卡号
	 *            key:随机码 ControlAuthorizationCode:控制授权码 serial_number:流水号
	 *            消约、关闭充电时必传 36位
	 * @param response
	 * @return JsonForCommon<String>
	 * @throws Exception
	 */
	@SuppressWarnings("rawtypes")
	@RequestMapping(value = "/enterpriselogins/controlCharger", method = RequestMethod.POST)
	@ResponseBody
	public JsonCommon<?> controlCharger(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 桩号 为16位数字
		String charger_id = request.getParameter("charger_id");
		OmsCharger charger = chargerService.findOneExample(new OmsCharger(charger_id), null, null);
		if (charger == null || charger.getCharger_type() == null) {
			return new JsonCommon(OmsConstant.ErrorCodeEnum.ChargerQueryNull.value(),
					OmsConstant.ErrorCodeEnum.ChargerQueryNull.desc());
		}
		// 枪口号 2位数字 01 02 ....
		String port_no = request.getParameter("port_no");
		if (charger.getCharger_type() == 1) {// 设备电流类型 1为直流
			switch (port_no) {
			case "00":
				port_no = "1";
				break;
			case "01":
				port_no = "1";
				break;
			case "02":
				port_no = "2";
				break;
			default:
				return new JsonCommon(OmsConstant.ErrorCodeEnum.ParamValueError.value(),
						OmsConstant.ErrorCodeEnum.ParamValueError.desc());
			}
		} else if (charger.getCharger_type() == 2) {// 2为交流
			switch (port_no) {
			case "0":
				port_no = "01";
				break;
			case "00":
				port_no = "01";
				break;
			case "1":
				port_no = "01";
				break;
			case "2":
				port_no = "02";
				break;
			default:
				return new JsonCommon(OmsConstant.ErrorCodeEnum.ParamValueError.value(),
						OmsConstant.ErrorCodeEnum.ParamValueError.desc());
			}
		} else {
			return new JsonCommon(OmsConstant.ErrorCodeEnum.ParamValueError.value(),
					OmsConstant.ErrorCodeEnum.ParamValueError.desc());
		}
		// qrcode 12位数字
		String qr_code = request.getParameter("qr_code");
		// 36位 数字 包含 桩号+端口号+14位时间+四位序号，其中端口号为两位，以01开始。',
		String serial_number = request.getParameter("serial_number");
		Pattern pattern = Pattern.compile("[0-9]*");
		Matcher isNumCharger_id = pattern.matcher(charger_id);
		Matcher isNumPort_no = pattern.matcher(port_no);
		Matcher isNumqr_code = pattern.matcher(qr_code);
		Matcher isNumSerial_numbe = pattern.matcher(serial_number);
		if (!isNumCharger_id.matches() || charger_id.length() != 16 || !isNumPort_no.matches() || port_no.length() != 2
				|| !isNumqr_code.matches() || qr_code.length() != 12) {// 判断 电桩号
																		// 枪口号
																		// 二维码是否由0-9的数字构成和判断他们的位数是否符合规则
			return new JsonCommon<String>(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgCode(),
					MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgInfo());
		}
		if (StringUtil.isNotBlank(serial_number)) {
			if (!isNumSerial_numbe.matches() || serial_number.length() > 40) {
				return new JsonCommon<String>(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgCode(),
						MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgInfo());
			}
			String strLeft = "", strRight = "";

			try {
				// 设置lenient为false.
				// 否则SimpleDateFormat会比较宽松地验证日期，比如2007/02/29会被接受，并转换成2007/03/01
				strLeft = serial_number.substring(serial_number.length() - 18);// 先去掉前18位桩号
																				// 枪口号
				strRight = strLeft.substring(0, 14);// 截取14位日期格式
				EnterpriseController.stringToDate(strRight, "yyyyMMddHHmmss");
			} catch (ParseException e) {
				// e.printStackTrace();
				// 如果throw
				// java.text.ParseException或者NullPointerException，就说明格式不对
				return new JsonCommon<String>(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgCode(),
						MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgInfo());
			}
		}

		String code = request.getParameter("code");
		String userPayCard = request.getParameter("userPayCard");
		String ControlAuthorizationCode = Ev3c2EncapsulationServiceImpl.getRandom4int();// 控制授权码

		if (StringUtil.isBlank(charger_id) || StringUtil.isBlank(port_no) || StringUtil.isBlank(qr_code)
				|| StringUtil.isBlank(code) || StringUtil.isBlank(userPayCard)
				|| StringUtil.isBlank(ControlAuthorizationCode)) {
			return new JsonCommon<String>(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgCode(),
					MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgInfo());

		}
		OmsCharger queryCharger = this.chargerService.findChargerDetailByChargerId(charger_id);
		if (queryCharger == null) {
			return new JsonCommon<String>(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgCode(),
					MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgInfo());

		}
		Map<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("chargerId", charger_id);
		paramMap.put("userCard", userPayCard);
		paramMap.put("portNo", port_no);
		paramMap.put("protocol_type", queryCharger.getProtocol_type());
		paramMap.put("protocol_version", queryCharger.getProtocol_version());
		switch (code) {
		case "1":
			paramMap.put("controlType", "04");// controlType控制类型 04为自动充满 BIN码
			paramMap.put("openRestrictedData", "00000000");// openRestrictedData开启限制数据开启限制数据
															// BIN码：不同充电模式下对应的计算量作为停机条件。自动充满停机方式下无意义。低字节在前，高字节在后。电量控制,单位为“度”，精确到0.01,传输数据放大100倍；时间控制，单位为“秒“，精确到1,；金额控制，单位为“元”，精确到0.01，传输数据放大100倍。
			paramMap.put("timeStart", "00000000");// timeStart定时启动 BCD码
			this.omsChargeService.startCharge(paramMap);
			return null;
		case "2":
			return this.omsChargeService.stopCharge(paramMap);
		case "3":
			return this.omsBespeakService.bespeak(paramMap);
		case "4":
			if (serial_number == null || "".equals(serial_number)) {
				return new JsonCommon<String>(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgCode(),
						MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgInfo());
			} else {
				paramMap.put("serial_number", serial_number);
				return this.omsBespeakService.cancelBespeak(paramMap);
			}
		default:
			return new JsonCommon<String>(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgCode(),
					MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgInfo());

		}
	}

	/**
	 * 查询站点分页信息
	 * 
	 * @param pageNo当前页码
	 * @param pageSize每页多少条
	 * @param current_state电站状态
	 *            (当前状态：1，运营中；2，安装中；3，规划中)，多个用下划线“_”隔开
	 * @param session
	 * @return
	 */
	@RequestMapping(value = "/enterpriselogins/getStationListByPage", method = RequestMethod.POST)
	@ResponseBody
	public JsonForList<?> getStationListByPage(@RequestParam(value = "pageNo", required = false) Integer pageNo,
			@RequestParam(value = "pageSize", required = false) Integer pageSize,
			@RequestParam(value = "current_state", required = false) String current_state, HttpSession session) {
		OmsStation station = new OmsStation();
		if (pageNo == null || pageSize == null || "".equals(pageSize) || "".equals(pageNo)) {// 默认从第一条开始
			pageNo = 1;
			pageSize = 20;
		}

		@SuppressWarnings("unchecked")
		JsonForList<OmsStation> jsonList = enterpriseService.getStationList(station, pageNo, pageSize, null, null,
				null);
		List<OmsStation> list = jsonList.getList();
		for (OmsStation stations : list) {
			List<OmsStationLocation> omsStationLocationList = this.enterpriseService
					.findByStationId(stations.getStation_id(), null, null, null, null);
			if (omsStationLocationList != null) {
				station.setLocationList(omsStationLocationList);
			}
		}

		return jsonList;
	}

	/**
	 * 通过电站ID查询单个站点详细信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/enterpriselogins/getStationById", method = RequestMethod.GET)
	@ResponseBody
	public JsonForList<?> getStationById(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String stationId = request.getParameter("station_id");
		List<OmsStation> list = stationService.getStationByIds(stationId);
		JsonForList<OmsStation> jsonForList = new JsonForList<>();

		if (list.size() < 1) {
			jsonForList.setCode(MsgCodeEnum.STATION_QUERY_ERROR.getMsgCode());
			jsonForList.setMsg(MsgCodeEnum.STATION_QUERY_ERROR.getMsgInfo());
		} else {
			jsonForList.setCode(MsgCodeEnum.SUCCESS.getMsgCode());
			jsonForList.setMsg(MsgCodeEnum.SUCCESS.getMsgInfo());
			jsonForList.setList(list);
		}
		return jsonForList;
	}

	/**
	 * 根据stationid获取可用桩的信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/enterpriselogins/getChargerByStationId", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public JsonForList<?> getChargerByStationId(HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		String stationId = request.getParameter("stationId");

		OmsCharger charger = new OmsCharger();
		charger.setStation_id(stationId);
		JsonForList<?> json = enterpriseService.getStationByPlantId(stationId);
		return json;

	}

	/**
	 * 根据桩的二维码获取桩的信息
	 * 
	 * @param qr_code
	 *            桩的二维码
	 */
	@RequestMapping(value = "/enterpriselogins/getChargerByQrCode", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public JsonCommon<?> getChargerByQrCode(@RequestParam(value = "qr_code", required = true) String qr_code,
			HttpSession session) {
		JsonCommon<OmsCharger> jsonList = new JsonCommon<>();
		Pattern pattern = Pattern.compile("[0-9]*");
		Matcher isNumCharger_id = pattern.matcher(qr_code);
		if (!isNumCharger_id.matches() || qr_code.length() != 12) {// 判断二维码是否是由12位数字组成
			jsonList.setCode(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgCode());
			jsonList.setMsg(MsgCodeEnum.AS_RPC_PARAM_FORMAT_ERROR.getMsgInfo());
			return jsonList;
		}
		try {
			OmsCharger charger = new OmsCharger();
			charger.setQr_code(qr_code);
			jsonList = chargerService.getLists(charger, qr_code);
		} catch (Exception e) {
			log.error("", e);
			jsonList.setCode(OmsConstant.ErrorCodeEnum.StationQueryException.value());
			jsonList.setMsg(OmsConstant.ErrorCodeEnum.StationQueryException.desc());
		}
		return jsonList;
	}

	public static void main(String[] args) {

		String str = "0000000000000120151013114250";
		String str1 = "";
		try {
			str1 = str.substring(str.length() - 14);
			Date data = EnterpriseController.stringToDate(str1, "yyyyMMddHHmmss");
			System.out.println(data);
		} catch (ParseException e) {

			// e.printStackTrace();
			System.out.println("+++++" + str1);
		}
		System.out.println(str);
	}

	/**
	 * String 转 Date
	 * 
	 * @param time
	 *            时间String
	 * @param geshi
	 *            格式"yyyy-MM-dd HH:mm:ss"
	 * @return Date
	 * @throws ParseException
	 */
	public static Date stringToDate(String time, String format) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.parse(time);
	}

	private boolean isLogin(String account, String token,HttpServletRequest request) {
		if(StringUtil.isBlank(token)) {
			return false;
		}
		HttpSession session = request.getSession();
		OmsOperList oper = (OmsOperList) session.getAttribute(AccountPrefix+account);
		if(oper == null) {
			return false;
		}
		String tokenOld = oper.getToken();
		if(token.equals(tokenOld)) {
			return true;
		}
		return false;
	}
	
}
